package com.controller;

import com.dao.MemberDao;
import com.dto.DTO;
import com.entity.Member;
import com.page.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller //@Controller注解是用spring容器生成 对象 默认对象名 memberController
@RequestMapping("/memberController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /memberController
public class MemberController {
	@Resource
	MemberDao memberDao;
	@RequestMapping("/getAllMember")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
	public DTO<Member> getAllMember(){
		System.out.println("查询全部社团");
		List<Member> members =  memberDao.getAllMembers();
		return new DTO<Member>(200, "查询全部社团",members);
	}


	@RequestMapping("/deleteMemberById/{aId}")
	@ResponseBody
	public DTO<Member> deleteMemberById(@PathVariable("aId") String aId){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println(aId+"删除社团");
		return new DTO<Member>(200, "删除"+aId+"社团成功");
	}


	@RequestMapping("/getMemberByPage")
	@ResponseBody
	public DTO<Member> getMemberByPage(PageInfo pageInfo){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询社团");
		List<Member> members = memberDao.getMemberByPage(pageInfo);
		System.out.println("周传奇");
		return new DTO<Member>(200, "分页查询社团成功",members);
	}
	@RequestMapping("/selectByMtno/{mtno}")
	@ResponseBody
	public DTO<Member> selectByMtno(@PathVariable("mtno") String mtno){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("按活动查看社团");
		List<Member> members = memberDao.selectByMtno( mtno );
		return new DTO<Member>(200, "按活动查看社团成功",members);
	}
}
